from typing import *


class Solution:

    def minimumString(self, a: str, b: str, c: str) -> str:
        s = (a, b, c)

        def join(a, b):
            for i in range(len(a)):
                A = a[i:min(len(a), i + len(b)):]
                B = b[:min(len(b), len(A)):]
                if A == B:
                    if len(B) == len(b):
                        return a
                    return a[:i:] + A + b[min(len(b), len(A))::]
            return a + b

        def f(a, b, c):
            ab = join(a, b)
            return join(ab, c)

        ans = None
        for i in range(3):
            for j in range(3):
                if i == j:
                    continue
                for k in range(3):
                    if k == i or k == j:
                        continue
                    r = f(s[i], s[j], s[k])
                    if ans is None or len(r) < len(ans) or (len(r) == len(ans)
                                                            and r < ans):
                        ans = r
        return ans


s = Solution()
print(s.minimumString("cab", "a", "b"))
